/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef TIMELINE_EVENT_H
#define TIMELINE_EVENT_H

#include <string>
#include <list>
#include <memory>

#include "napi/native_api.h"
#include <map>

namespace OHOS {
namespace Msdp {
struct TimelineEventListener {
    int32_t eventArea;
    napi_ref handlerRef = nullptr;
};

class TimelineEvent {
public:
    TimelineEvent(napi_env env, napi_value thisVar);
    TimelineEvent() {};
    virtual ~TimelineEvent();

    virtual void on(const int32_t& eventArea, napi_value handler);
    virtual void off(const int32_t& eventArea);
    virtual void once(const int32_t& eventArea, size_t argc, const napi_value* argv);

protected:
    napi_env env_;
    napi_ref thisVarRef_;
    std::map<int32_t, std::shared_ptr<TimelineEventListener>> eventMap_;
};

} // namespace Msdp
} // namespace OHOS
#endif // TIMELINE_EVENT_H